*** Authors: Alex Badas and Beth Simas
*** Title: The Supreme Court as an Electoral Issue: Evidence from Three Studies
*** Journal: Political Science Research and Methods 
clear

log using "BadasSimasPSRMreplication.log", replace

///: Study 1

///: Load the data
use Study1NORCSurvey.dta 
   ///: Creating relvative average and average importance measures 
 gen missA=0
 replace missA=1 if Q7A==0
 gen missB=0
 replace missB=2 if Q7B==0
 gen missC=0
 replace missC=3 if Q7C==0
 gen missD=0
 replace missD=4 if Q7D==0
 gen missE=0
 replace missE=5 if Q7E==0
 gen missF=0
 replace missF=6 if Q7F==0
 gen missG=0
 replace missG=7 if Q7G==0
 gen missH=0
 replace missH=8 if Q7H==0
 gen missI=0
 replace missI=9 if Q7I==0
 gen missJ=0
 replace missJ=10 if Q7J==0
 gen missK=0
 replace missK=11 if Q7K==0
 gen missL=0
 replace missL=12 if Q7L==0
 gen missM=0
 replace missM=13 if Q7M==0
 gen missN=0
 replace missN=14 if Q7N==0
 gen missO=0
 replace missO=15 if Q7O==0
 gen missP=0
 replace missP=16 if Q7P==0
 gen missQ=0
 replace missQ=17 if SupremeCourt==.
 gen missR=0
 replace missR=18 if Q7R==0
 
 egen random=rowtotal(missA-missR)

 recode Q7A-Q7R (0=.), gen(a b c d e f g h i j k l m n o p q r)
 egen fullave=rowmean(a b c d e f g h i j k l m n o p r)
 gen SCimport=SupremeCourt-fullave
 
  
 
 ///: Recode Party Variables 
  gen indbase=.
 replace indbase=1 if demo==1
 replace indbase=2 if demo==2
 replace indbase=3 if indep==1
 replace indbase=0 if indep==3
 replace indbase=4 if indep==2
 replace indbase=5 if repub==2
 replace indbase=6 if repub==1
 
 recode indbase (0=4) (4=5) (5=6) (6=7), gen(pid7)
 recode pid7 (1 2 3=1) (4=0) (5 6 7=2), gen(pid3)
 recode pid7 (1 7=3) (2 6=2) (3 5=1) (4=0), gen(pidx)
 
 ///: Generate White indicator variable 
 gen white = 1 if raceth ==1
 recode white . = 0 
 recode gender 1=0 2=1
 
 ///: Figure 1. Distrubtion of Supreme Court Importance
 histogram SCimport, xline(-.1513622)
 graph save Figure1, replace
 
 ///: Table 1. OLS Regression: Relative Importance of Supreme Court Appointments  
reg SCimport fullave b4.pid7 gender white edu age hhincome SURV_MOD  [pweight = finalwt]
///: Figure 2 
margins pid7, plot 
graph save Figure2, replace



///: Online Appendix for Study 1

///: Appendix Table 1. Summary stats. 
sum SCimport fullave pid7 gender white edu age hhincome SURV_MOD if SCimport!=.

///: Appendix Table 2, Column 1
 reg Lik SCimport fullave b7.pid7 gender white edu age hhincome SURV_MOD  [pweight = finalwt]
///: Appendix Figure 1 
margins, at(SCimport=(-4(.5)2)) plot
graph save AppendixFigure1, replace 
///: Appendix Table 2, Column 2 
gen certain = 0
replace certain = 1 if Lik ==11

logit certain SCimport fullave b7.pid7 gender white edu age hhincome SURV_MOD  [pweight = finalwt]
///: Appendix Figure 2 
margins, at(SCimport=(-4(.5)2)) plot
 graph save AppendixFigure2, replace

clear

///: Study 2 
///: Load the data
use study2CCES.dta 

///: Generate congruence variables 
gen votedem=.
replace votedem=1 if SenCand1Party=="Democratic" & CC18_410b==1
replace votedem=0 if SenCand2Party=="Republican" & CC18_410b==2

gen deminc=.
replace deminc=1 if inputstate==9 | inputstate==10 | inputstate==12
replace deminc=1 if inputstate==15 | inputstate==18 | inputstate==24
replace deminc=1 if inputstate==25 | inputstate==26 | inputstate==27
replace deminc=1 if inputstate==29 | inputstate==30 | inputstate==34
replace deminc=1 if inputstate==35 | inputstate==36 | inputstate==38
replace deminc=1 if inputstate==39 | inputstate==42 | inputstate==44
replace deminc=1 if inputstate==51 | inputstate==53 | inputstate==54 | inputstate==55
replace deminc=0 if inputstate==28 | inputstate==31 | inputstate==32
replace deminc=0 if inputstate==48 | inputstate==56

gen voteinc=1 if votedem==1 & deminc==1
replace voteinc=1 if votedem==0 & deminc==0
replace voteinc=0 if votedem==1 & deminc==0
replace voteinc=0 if votedem==0 & deminc==1

gen ng_y=.
replace ng_y=1 if deminc==0
replace ng_y=0 if deminc==1
replace ng_y=1 if inputstate==18 | inputstate==38 | inputstate==54

gen bk_y=.
replace bk_y=1 if deminc==0
replace bk_y=0 if deminc==1

gen ng_same=.
replace ng_same=1 if ng_y==1 & Gorsuch_support==1
replace ng_same=1 if ng_y==0 & Gorsuch_support==0
replace ng_same=0 if ng_y==1 & Gorsuch_support==0
replace ng_same=0 if ng_y==0 & Gorsuch_support==1

gen bk_same=.
replace bk_same=1 if bk_y==1 & Kavanaugh_support==1
replace bk_same=1 if bk_y==0 & Kavanaugh_support==0
replace bk_same=0 if bk_y==1 & Kavanaugh_support==0
replace bk_same=0 if bk_y==0 & Kavanaugh_support==1

egen courttot=rowtotal(ng_same bk_same)


recode CC18_321c (1=1) (2=0), gen(resp_abort_y)
gen inc_abort_y=1 if deminc==0
replace inc_abort_y=0 if deminc==1
replace inc_abort_y=1 if inputstate==42 | inputstate==54
gen abort_same=1 if resp_abort_y==1 & inc_abort_y==1
replace abort_same=1 if resp_abort_y==0 & inc_abort_y==0
replace abort_same=0 if resp_abort_y==1 & inc_abort_y==0
replace abort_same=0 if resp_abort_y==0 & inc_abort_y==1

recode pid7 (8=.), gen(pidr)
gen pidd=abs(pidr-8)
gen pidinc=pidr if deminc==0
replace pidinc=pidd if deminc==1
recode pid7 8 = . 


recode CC18_334A CC18_334I CC18_334J (8=.), gen(lcself lcsen1 lcsen2)

gen incdist=abs(lcself-lcsen1) if deminc==1
replace incdist=abs(lcself-lcsen2) if deminc==0

gen incdist01=incdist/6
gen pidinc01=(pidinc-1)/6


///: Generate Knowledge
recode CC18_309a (1=1) (else=0), gen(k1)
recode CC18_309b (1=1) (else=0), gen(k2)
gen k3=0
replace k3=1 if CC18_310a==2 & CurrentGovParty=="Republican"
replace k3=1 if CC18_310a==3 & CurrentGovParty=="Democratic"
replace k3=1 if CC18_310a==4 & CurrentGovParty=="Independent"
gen k4=0
replace k4=1 if CC18_310b==2 & CurrentSen1Party=="Republican"
replace k4=1 if CC18_310b==3 & CurrentSen1Party=="Democratic"
replace k4=1 if CC18_310b==4 & CurrentSen1Party=="Independent"
gen k5=0
replace k5=1 if CC18_310c==2 & CurrentSen2Party=="Republican"
replace k5=1 if CC18_310c==3 & CurrentSen2Party=="Democratic"
replace k5=1 if CC18_310c==4 & CurrentSen2Party=="Independent"
gen k6=0
replace k6=1 if CC18_310d==2 & CurrentHouseParty=="Republican"
replace k6=1 if CC18_310d==3 & CurrentHouseParty=="Democratic"
replace k6=1 if CC18_310d==4 & CurrentHouseParty=="Independent"
egen know=rowmean(k1 k2 k3 k4 k5 k6)



///: Create indicator for verified voter 
gen verified=0
replace verified=1 if CL_2018gvm!=.

///: Recode income missing
recode faminc_new (97=.), gen(income)

///: Figure 3
   ///: Remove independents 
gen repdem = . 
replace repdem = 1 if pid7 >4
replace repdem =2 if pid7 <4

histogram courttot, discrete width(1) percent by(deminc repdem, rows(1))
graph save Figure3, replace
///: Table 2: Logit models predicting incumbent vote 

///: Table 2 Column 1: Logit models for everyone
logit voteinc (i.courttot abort_same c.pidinc c.incdist)##c.know gender white educ age /// 
income i.inputstate if verified==1

///: Figure 4 
margins courttot, at(know=(.0 .1 to 1)) plot
graph save Figure4, replace

///: Figure 5 
margins, dydx(courttot abort_same) at(know=(.0 .1 to 1)) plot(legend(ring(0)))
graph save Figure5, replace


///: Table 2 Column 2: Logit models for Republicans 
logit voteinc (i.courttot abort_same c.pidinc c.incdist)##c.know gender white educ age ///
income i.inputstate if verified==1& pid7>4

///: Figure 6, left pane
margins courttot, at(know=(.0 .1 to 1)) plot
graph save Figure6left, replace

///: Figure 7, left pane 
margins, dydx(courttot abort_same) at(know=(.0 .1 to 1)) plot
graph save Figure7left, replace

///: Table 2 Column 3: Logit models for Democrats 
logit voteinc (i.courttot i.abort_same c.pidinc c.incdist)##c.know gender white educ age ///
income i.inputstate if verified==1& pid7<4

///: Figure 6, right pane
margins courttot, at(know=(.0 .1 to 1)) plot
graph save Figure6right, replace

///:Figure 7, right pane
margins, dydx(courttot abort_same) at(know=(.0 .1 to 1)) plot
graph save Figure7right, replace

///: Online Supplement for Study 2

///:Summary statistics. Table 3. 

sum voteinc courttot ng_same bk_same abort_same know incdist pidinc ///
gender white edu age income if voteinc!=.

///: Correlation between Congruence Items. Table 4. 

corr ng_same bk_same courttot incdist pidinc abort_same


///Congruence by Party, Member of the Mass Public. Table 5. 
gen pid3 = .
replace pid3=1 if pid7 == 1 | pid7==2 | pid7==3
replace pid3=2 if pid7==4
replace pid3=3 if pid7==5 | pid7==6 |pid7==7

by pid3, sort: summarize courtt if voteinc !=.

///: Analysis of indivdual nominees. All. Table 7, Column 1. 
logit voteinc (i.ng_same i.bk_same abort_same)##c.know c.incdist01 ///
pidinc01 gender white educ age income i.inputstate if verified==1

///: Figure 3, left most panel. All. 
margins, dydx(ng_same bk_same abort_same) at(know=(.0 .1 to 1)) plot
graph save AppendixFigure3left, replace

///: Analysis of individual nominees. Republicans. Table 7, Column 2.
logit voteinc (i.ng_same i.bk_same abort_same)##c.know c.incdist ///
 pidinc01 gender white educ age income i.inputstate if verified==1 & pid7<4

 ///:Figure 3, middle panel. Republicans.
margins, dydx(ng_same bk_same abort_same) at(know=(.0 .1 to 1)) plot
graph save AppendixFigure3middle, replace

///: Analysis of individual nominees. Democrats. Table 7, Column 3. 
logit voteinc (i.ng_same i.bk_same abort_same)##c.know c.incdist ///
pidinc01 gender white educ age income i.inputstate if verified==1 & pid7>4

///: Figure 3, right most panel. Democrats.
margins, dydx(ng_same bk_same abort_same) at(know=(.0 .1 to 1)) plot
graph save AppendixFigure3right, replace

///: Congruence of Judicial Confirmation Votes and Partisan Congruence Table 8
logit voteinc (i.courttot )##c.pidinc abort_same c.incdist know gender white educ age /// 
income i.inputstate 

///: Congruence of Judicial Confirmation Votes and Partisan Congruence Figure 4
margins courttot, at(pidinc=(1(1)7)) plot
graph save AppendixFigure4, replace

///: Three-way Interaction Nominees x Knowledge x Party. Table 9

logit voteinc (i.courttot abort_same c.pidinc c.incdist)##c.know ///
i.courttot##c.know##i.repdem gender white educ age income i.inputstate if verified==1

///: Figure 5. 
margins, dydx(courttot) at(know=(.0 .1 to 1)) by(repdem) post plot
graph save AppendixFigure5, replace

clear


log close
